<template>
    <div>
        <el-card>
<<<<<<< HEAD
            <el-input style="width:440px" @clear="searchUser" clearable v-model="searchForm.username" placeholder="请输入用户姓名"
                class="input-with-select" size="small">
=======
            <el-input style="width:440px" @clear="searchUser" clearable v-model="searchForm.name" placeholder="请输入用户姓名" class="input-with-select">
>>>>>>> 61245a080de0a6db0e91cdacdbb6409c58c67aa6
                <template #append>
                    <el-button icon="Search" @click="searchUser" />
                </template>
            </el-input>
<<<<<<< HEAD
            <el-button type="primary" style="margin-left:10px;" @click="addHandle()">新增</el-button>
            <el-table :data="tableData" border style="width: 100%;margin-top:20px">
                <el-table-column prop="username" label="账号" header-align="center" align="center" />
                <el-table-column prop="realname" label="姓名" header-align="center" align="center" />
                <el-table-column prop="sex_dictText" label="性别" width="180" header-align="center" align="center" />
                <el-table-column prop="phone" label="手机号" width="180" header-align="center" align="center" />
                <el-table-column prop="orgCodeTxt" label="部门" header-align="center" align="center" />
                <el-table-column prop="status_dictText" label="状态" width="180" header-align="center" align="center" />
                <el-table-column label="操作" width="200" fixed="right" header-align="center" align="center">
                    <template #default="scope">
                        <el-button type="danger" size="small" @click="deleteUser(scope.row.id)">删除</el-button>
                        <el-button type="" size="small" @click="detaiUser(scope.row.id)">详情</el-button>
=======
            <el-table :data="tableData" border style="width: 100%;margin-top:20px">
                <el-table-column prop="username" label="账号" header-align="center" align="center" />
                <el-table-column prop="realname" label="姓名"  header-align="center" align="center"/>
                <el-table-column prop="sex_dictText" label="性别" width="180" header-align="center" align="center"/>
                <el-table-column prop="phone" label="手机号" width="180" header-align="center" align="center"/>
                <el-table-column prop="orgCodeTxt" label="部门" header-align="center" align="center"/>
                <el-table-column prop="status_dictText" label="状态" width="180" header-align="center" align="center"/>
                <el-table-column label="操作" width="200" fixed="right" header-align="center" align="center">
                    <template #default="scope">
                        <el-button type="danger" size="small" @click="deleteUser(scope.row.id)">删除</el-button>
                        <el-button size="small"
                            @click="() => router.push({ path: '/user/detail', query: { id: scope.row.id } })">详情</el-button>
>>>>>>> 61245a080de0a6db0e91cdacdbb6409c58c67aa6
                    </template>
                </el-table-column>
            </el-table>
            <!-- 分页 -->
            <el-pagination style="margin-top:20px" :current-page="searchForm.current" :page-size="searchForm.size"
                :page-sizes="[10, 20, 30, 40]" layout="->,total, sizes, prev, pager, next, jumper" :total="total"
                @size-change="handleSizeChange" @current-change="handleCurrentChange" />
        </el-card>
<<<<<<< HEAD
        <!-- 编辑新增 -->
        <AddOrEdit :dialogVisible="showModal" ref="addOrEditRef" :formData="formData" :dialogId="dialogId" @close="closeDialog"></AddOrEdit>
        <!-- <el-dialog v-model="dialogTableVisible" title="Shipping address">
            eeeeeeeeee
        </el-dialog> -->
=======
>>>>>>> 61245a080de0a6db0e91cdacdbb6409c58c67aa6
    </div>
</template>

<script setup>
import userApi from "../../api/user";
<<<<<<< HEAD
import { onMounted, reactive, ref, nextTick } from "vue";
import { ElMessage, ElMessageBox } from 'element-plus';
import { useRouter } from 'vue-router'
import AddOrEdit from "./modal/addOrEdit.vue";
=======
import { onMounted, reactive, ref } from "vue";
import { ElMessage, ElMessageBox } from 'element-plus';
import { useRouter } from 'vue-router'
>>>>>>> 61245a080de0a6db0e91cdacdbb6409c58c67aa6
const router = useRouter();
// Dom 挂载之后
onMounted(() => {
    getUserList();
})
// 用户数据
<<<<<<< HEAD
const tableData = ref([]);
const total = ref(0);
const formData = ref({});
const dialogId = ref('');
const showModal = ref(false);
const addOrEditRef = ref();
const dialogTableVisible = ref(false);
const searchForm = reactive({
    username: ''
})
// 搜索条件
const queryParams = reactive({
    username: '',
    pageNo: 1,
    pageSize: 10
})

// 获取用户列表
const getUserList = async () => {
    if (searchForm.username) {
        queryParams.username = '*' + searchForm.username + '*'
    } else {
        queryParams.username = ''
    }
    const res = await userApi.getUserList(queryParams);
=======
let tableData = ref([]);
let total = ref(0);
// 搜索条件
const searchForm = reactive({
    current: 1,
    size: 10,
    name: ''
})
// 获取用户列表
const getUserList = async () => {
    const res = await userApi.getUserList(searchForm);
>>>>>>> 61245a080de0a6db0e91cdacdbb6409c58c67aa6
    console.log(res);
    tableData.value = res.data.result.records;
    total.value = res.data.result.total;
}
<<<<<<< HEAD
const closeDialog = () => {
    showModal.value = false
    getUserList()
}
=======
>>>>>>> 61245a080de0a6db0e91cdacdbb6409c58c67aa6
const handleSizeChange = (size) => {
    searchForm.size = size;
    getUserList();
}
const handleCurrentChange = (current) => {
    searchForm.current = current;
    getUserList();
}
const searchUser = () => {
    searchForm.current = 1;
    getUserList();
}
<<<<<<< HEAD
const addHandle = (tableInfo) => {
    showModal.value = true;
    nextTick(() => {
        //因为是ref创建的，所以得加.value 
        addOrEditRef.value.getDepartData()
        if (tableInfo && tableInfo.id) {
            dialogId.value = tableInfo.id
            Object.assign(formData.value, tableInfo);
        }
    })



}
=======
>>>>>>> 61245a080de0a6db0e91cdacdbb6409c58c67aa6
// 删除用户
const deleteUser = (id) => {
    ElMessageBox.confirm(
        '确定要删除该用户信息吗?',
        {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
        }
    ).then(async () => {
        const res = await userApi.delUser({ id: id });
        if (res.data.success) {
            ElMessage.success("删除成功")
            getUserList();
        } else {
            ElMessage.error("删除失败")
        }
    }).catch(() => {
        ElMessage({
            type: 'info',
            message: '取消删除',
        })
    })
}
</script>

<<<<<<< HEAD
<style lang="scss" scoped></style>
=======
<style lang="scss" scoped>

</style>
>>>>>>> 61245a080de0a6db0e91cdacdbb6409c58c67aa6
